<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.control.CourseControl"%>
<%@ page import="com.control.UserControl"%>
<%@ page import="com.model.Course"%>
<%@ page import="com.model.User"%>
<%@ page import="com.util.PageResultSet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>选课</title>
	</head>
	<body>
		<%
			request.setCharacterEncoding("UTF-8");
			String ToolBar = "";
	    	int curPage = 1;
			int student_id = (Integer) session.getAttribute("id");		
		%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							选课情况
						</legend>
						<form action="select_index.jsp" name="form1" method="post"><br><table width="60%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1"  width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF"> 
													课程名</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF"> 
												           教师<br></td>
												<td width="5%" height="25" align="center" bgcolor="#D9F0FF"> 
												          操作<br></td>
								</tr>
								
								<%
									CourseControl cc = new CourseControl();
									UserControl uc = new UserControl();
									ArrayList<Course> list = new ArrayList<Course>();
									list = cc.selectCourse(student_id);
									if(request.getParameter("cur_page")!= null) {
										curPage = Integer.parseInt(request.getParameter("cur_page")); 
									}
									PageResultSet p = new PageResultSet(list,curPage);
									ArrayList<Course> nowlist = new ArrayList<Course>();
									nowlist = (ArrayList<Course>)p.getData();
										for(int i=0; i<nowlist.size(); i++) {
											Course course = nowlist.get(i);
											int teacher_id = course.getTeacher_id();
											User user = uc.getUser(teacher_id);
											
											String hrefValue = null;
											String hrefLocation = null;
											int course_id = course.getId();
											hrefLocation =  "select_chuli.jsp?course_id=" + course_id;
											if(cc.Lock(course_id)){
												hrefValue = "锁定";
											}
											else{
												if(course.isType()){
													hrefValue = "退课";
													hrefLocation += "&type=1" ;
												}else{
												  	hrefValue = "选课";
												  	hrefLocation += "&type=0" ;
												}
											}
											
											
								%>
								 	<tr>
        								<td height="25" align="center"><%=course.getName()%></td>
 										<td height="25" align="center"><%=user.getName()%></td>
 										<td height="25" align="center">
 									<%
 										if(cc.Lock(course_id)){
 									 %>
 										 <%=hrefValue %></td>
 									<%}else{
 									 %>
 									 	 <a href=<%= hrefLocation%> > <%=hrefValue %></a></td>
 									</tr>
   									<%}}
   										
										String fileName = "select_index.jsp";
										ToolBar = p.getToolBar(fileName);
									%>
							</table>
							<%=ToolBar %>
							</td>
							</tr>
							</table><br></form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
